package ru.eas.packer;

import static java.lang.Math.abs;

/**
 * @author aesipov
 */
public class PositionedBox {
    private Box box;
    private Point point;

    public PositionedBox(Box box, Point point) {
        this.box = box;
        this.point = point;
    }

    public boolean isIntersect(PositionedBox positionedBox) {
        Point otherPoint = positionedBox.getPoint();
        Box otherBox = positionedBox.getBox();
        return
                (abs(point.getX() - otherPoint.getX()) * 2 < (box.getWidth() + otherBox.getWidth())) &&
                (abs(point.getY() - otherPoint.getY()) * 2 < (box.getHeight() + otherBox.getHeight())) &&
                (abs(point.getZ() - otherPoint.getZ()) * 2 < (box.getDepth() + otherBox.getDepth()));
    }

    public Box getBox() {
        return box;
    }

    public Point getPoint() {
        return point;
    }

    public Point getTopPoint() {
        return new Point(point.getX(), point.getY(), point.getZ() + box.getHeight());
    }

    public Point getLeftPoint() {
        return new Point(point.getX() + box.getWidth(), point.getY(), point.getZ());
    }

    public Point getRightPoint() {
        return new Point(point.getX(), point.getY()  + box.getDepth(), point.getZ());
    }
}
